/**
 * @description:
 * @Author: wuzhenbin
 * @CreateTime: 2025-02-14
 */
public class leetcode_238 {
    public static void main(String[] args) {

    }

    //数组题目中最重要的思想 分块 前n项和!!!  (分治思想的体现
    public int[] productExceptSelf(int[] nums) {
        int[] prefix = new int[nums.length];
        prefix[0] = 1;
        int[] suffix = new int[nums.length];
        for (int i = 1; i < nums.length; i++) {
            prefix[i]=prefix[i-1]*nums[i-1];
        }
        suffix[nums.length-1]=1;
        for (int i = nums.length-2; i >=0 ; i--) {
            suffix[i] = suffix[i+1]*nums[i+1];
        }
        int[] res = new int[nums.length];
        for (int i = 0; i < nums.length; i++) {
            res[i]=prefix[i]*suffix[i];
        }
        return res;
    }
}
